package org.apache.pdfbox.arktaohtml.slide;

import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;

/**
 * 该对象表示 "编辑器v2.x 数据文档 " 中的一个 "新页面",
 * 在 PowerPoint 中表示一张幻灯片
 * 因此我这里也用 slide 命名
 */
@Slf4j
public class ASlide {
    private String id;
    //页面唯一标识，8位，由数字和大小写字母组成        string

    //private String title;
    /*页面标题（讲义标题）string */
    //private String remark;
    /*页面讲义内容 string*/
    //private int duration;
    /*预计页面演示持续时间，单位 分钟number */

    private boolean extended;
    //是否开启扩展画布 bool false
    private int[] extendRange = {0, 0, 0, 0};
    /*扩展画布范围，单位 pxarray[0,0,0,0] */


    //背景. backgroundType 与  backgroundValue 用于生成 background 的值.
    //| **类型** | **值**                                                  | **补充**                                                     |
    //| -------- | ------------------------------------------------------- | ------------------------------------------------------------ |
    //| 纯色     | `['solid', '颜色值']`                                   |                                                              |
    //| 图片     | `['image', '图片地址']`                                 |                                                              |
    //| 渐变     | `['gradient', { type: '渐变类型', color: '渐变颜色' }]` | 渐变类型可选：`top, bottom, left, right, topLeft, topRight, bottomLeft, bottomRight` |
    //背景类型
    private ABackgroundType backgroundType;
    //背景值
    private String backgroundValue;
    private String background;
    //页面背景，具体见页面背景数据表*array

    private ArrayList<AElement> els;
    //页面内元素集合，格式为：`[{元素属性}, {元素属性}, ...]`元素在集合中的位置同时代表其在画布中的层级，**具体属性****见各元素数据表

    public ASlide() {
        this.id = String.valueOf(Math.ceil(Math.random()*1000));
        this.extended = false;
        this.els = new ArrayList<>();
    }


    public void setBackgroundValue(String backgroundValue) {
        switch (backgroundType) {
            case SOLID: {
                setBackgroundRGB(backgroundValue);
                break;
            }
            case IMAGE: {
                //setBackgroundImage(backgroundValue);
                setBackgroundImage(backgroundValue);
                break;
            }
            case GRADIENT: {
                log.error("Unprocessed background type {}", backgroundType);
                break;
            }
        }
    }

    public boolean isExtended() {
        return extended;
    }

    public void setExtended(boolean extended) {
        this.extended = extended;
    }

    public int[] getExtendRange() {
        return extendRange;
    }

    public void setExtendRange(int[] extendRange) {
        this.extendRange = extendRange;
    }

    public String[] getBackground() {
        if (background==null) return new String[]{};
        return new String[]{backgroundType.name().toLowerCase(), backgroundValue};
    }

    public ABackgroundType getBackgroundType() {
        return backgroundType;
    }

    public void setBackgroundType(ABackgroundType backgroundType) {
        this.backgroundType = backgroundType;
    }

    public void setBackgroundRGB(String background) {
        this.backgroundValue = background;
    }

    public ArrayList<AElement> getEls() {
        return els;
    }

    public void setEls(ArrayList<AElement> els) {
        this.els = els;
    }

    public void setBackgroundImage(String background) {
        //this.backgroundValue = "url(\"" + background + "\")";
        this.backgroundValue = background;
    }

    public void addElement(AElement e) {
        if (e instanceof AImage) {
            this.els.add((AImage) e);
        } else if (e instanceof AText) {
            this.els.add((AText) e);
        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
}







